<?php
####################################################
#    cart.php
####################################################
#    handles the shopping cart 
#####################################################
// Include e107 class, Header and the e107Shop classes
require_once("../../class2.php");
require_once("library/api.php");
require_once(e_HANDLER."np_class.php");
$tax_method = '';
$tax_rate = '';
$productID = $tp->toDB($_REQUEST['product']);
$lineID = $tp->toDB($_POST["lineid"]);
$quantity = (int) $_REQUEST["quantity"];
if ($_GET["action"]=="add"){
    // Action if we are adding something to the cart
    $product_option_count = (int)$_POST["option_count"];
    for($i=0; $i< $product_option_count; $i++) {
        $product_option .= $_POST["product_option".$i]."|";
    }
    $product_option = substr_replace($product_option, '', -1, 1);
    $functstatus = e107shop_add_products_to_cart($productID, 
    $_REQUEST["quantity"], $product_option, $cart_id, $_POST["field1"], $_POST["field2"], 
    $_POST["field3"], $_POST["field4"], $_POST["field5"], $_POST["field6"], $_POST["field7"], 
    $_POST["field8"], $_POST["field9"], $_POST["field10"], $_POST["field11"], $_POST["field12"], 
    $_POST["field13"], $_POST["field14"], $_POST["field15"], $_POST["field16"], $_POST["field17"], 
    $_POST["field18"], $_POST["field19"], $_POST["field20"]);
    require_once(HEADERF);
    e107shop_display_custom_page_info(e_PAGE, "top");
    if ($functstatus == TRUE) $ns->tablerender(lan_shopping_cart, e107shop_display_shopping_cart($cart_id));
    else $ns->tablerender(lan_shopping_cart, "<center>".lan_global_error."</center>");
} else if($_GET["action"]=="update") {
    // Action if we are updating cart
    e107shop_update_cart($lineID, $quantity, $productID);
    require_once(HEADERF);
    e107shop_display_custom_page_info(e_PAGE, "top");
    $ns->tablerender(lan_shopping_cart, e107shop_display_shopping_cart($cart_id));
} else if($_GET["action"]=="delete") {
    // Action if we are deleting a product from the cart
    e107shop_update_cart($lineID, "0", $productID);
    require_once(HEADERF);
    e107shop_display_custom_page_info(e_PAGE, "top");
    $ns->tablerender(lan_shopping_cart, e107shop_display_shopping_cart($cart_id));
} else if($_GET["action"]=="empty"){
    // Action to perform if emptying the cart
    e107shop_empty_cart($cart_id);
    require_once(HEADERF);
    e107shop_display_custom_page_info(e_PAGE, "top");
    $ns->tablerender($shopsettings["store_name"], e107shop_display_shopping_cart($cart_id));
} else {
    // Action to just display the cart
    require_once(HEADERF);
    e107shop_display_custom_page_info(e_PAGE, "top");
    $ns->tablerender(lan_shopping_cart, e107shop_display_shopping_cart($cart_id));
}

e107shop_display_custom_page_info(e_PAGE, "bottom");
require_once(FOOTERF);
?>